package main

import (
	"context"
	"fmt"
	"hello_grpc/service"
	"net"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

type server struct {}
func (s *server) SayHello(ctx context.Context, in *service.HelloRequest) (*service.HelloReply, error) {
	return &service.HelloReply{Message: "hello " + in.Name}, nil
}
func (s *server) OpenDoor(ctx context.Context, in *service.OpenDoorReq)(*service.OpenDoorResult,error){
	return &service.OpenDoorResult{Message:"开门",Code:1},nil
}
func main() {
	lis, err := net.Listen("tcp", ":8082")
	if err != nil {
		fmt.Printf("监听端口失败: %s", err)
		return
	}
	// 创建gRPC服务器
	s := grpc.NewServer()
	// 注册服务
	service.RegisterRouterServer(s, &server{})

	reflection.Register(s)
	err = s.Serve(lis)
	if err != nil {
		fmt.Printf("开启服务失败: %s", err)
		return
	}
}
